[WIP] rpc: recycle request/response memory across gRPC calls #137806
+365
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit creates a better
grpc.PreparedMsg
and uses it in both directions of theBatchStream
RPC.grpc.PreparedMsg
was introduced in this commit (see grpc/grpc-go#2432) as a way to provide more control over message encoding, but it doesn't actually allow for memory reuse. Notably, each use ofPreparedMsg.Encode
still allocates all memory afresh. As far as I can tell, the only thing it does is allow for parallel serialization/compression.In this commit, we exploit the API with a few sprinkles of unsafe magic and our own implementation to allow for reuse of the memory buffers used for serializing and compressing requests and responses.
Don't merge unless we're ready to abuse grpc on a whole new level. It is probably better just to fork at this point. Or we could try to upgrade to a newer version of gRPC that contains grpc/grpc-go#6619.
Epic: None
Release note: None